﻿using System;
using System.Globalization;
using System.Xml.Serialization;
using System.IO;
using System.Text;

namespace TwitterXml
{
    [XmlRootAttribute(ElementName = "direct_message", IsNullable = false)]
    public class DirectMessage
    {

        #region Private Fields

        private const string twitterCreatedAtDateFormat = "ddd MMM dd HH:mm:ss zzzz yyyy"; // Thu Apr 26 01:36:08 +0000 2007

        private int id;
        private string text;
        private int sender_id;
        private int recipient_id;
        private string created_at;
        private string sender_screen_name;
        private string recipient_screen_name;
        private User sender;
        private User recipient;

        #endregion Private Fields


        #region Public Properties

        [XmlElement(ElementName = "id")]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [XmlElement(ElementName = "text")]
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        [XmlElement(ElementName = "sender_id")]
        public int Sender_Id
        {
            get { return sender_id; }
            set { sender_id = value; }
        }

        [XmlElement(ElementName = "recipient_id")]
        public int Recipient_Id
        {
            get { return recipient_id; }
            set { recipient_id = value; }
        }

        [XmlElement(ElementName = "created_at")]
        public string Created_At
        {
            get { return created_at; }
            set { created_at = value; }
        }

        [XmlIgnore]
        public DateTime CreatedAt
        {
            get 
            { 
                return DateTime.ParseExact(
                created_at,
                twitterCreatedAtDateFormat, 
                CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces); 
            }
            set { created_at = value.ToString(twitterCreatedAtDateFormat); }
        }

        [XmlElement(ElementName = "sender_screen_name")]
        public string Sender_Screen_Name
        {
            get { return sender_screen_name; }
            set { sender_screen_name = value; }
        }

        [XmlElement(ElementName = "recipient_screen_name")]
        public string Recipient_Screen_Name
        {
            get { return recipient_screen_name; }
            set { recipient_screen_name = value; }
        }

        [XmlElement(ElementName = "sender")]
        public User Sender
        {
            get { return sender; }
            set { sender = value; }
        }

        [XmlElement(ElementName = "recipient")]
        public User Recipient
        {
            get { return recipient; }
            set { recipient = value; }
        }

        #endregion Public Properties


        #region Contructors

        public DirectMessage()
        {
        }

        public DirectMessage(int id, string text, int sender_id, int recipient_id, string created_at, string sender_screen_name, string recipient_screen_name, User sender, User recipient)
        {
            this.id = id;
            this.text = text;
            this.sender_id = sender_id;
            this.recipient_id = recipient_id;
            this.created_at = created_at;
            this.sender_screen_name = sender_screen_name;
            this.recipient_screen_name = recipient_screen_name;
            this.sender = sender;
            this.recipient = recipient;
        }

        #endregion Constructors

    }
}
